﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DecisionFramework.Logging;
 
namespace DecisionFramework.Logging.Internal
{
	/// <summary>
	/// Represents a Windows 7 like log channel interface: 
    /// CompanyName.ContainerOrTechnology.Component {Admin,Operational,Analytic,Debug}.
	/// </summary>
	/// <remarks> 
	/// <para></para>
	/// Author: Greg Cowin
	/// </remarks> 
	public class Channel :  IChannel
	{
        /// <summary>
        /// Creates a channel with the given channel type, company name, and container name.
        /// </summary>
        /// <param name="aChannelType">The channel type.</param>
        /// <param name="companyName">The company name.</param>
        /// <param name="containerName">The container name.</param>
		public Channel(ChannelType aChannelType, string companyName, string containerName)
		{
			ChannelType = aChannelType;
			CompanyName = companyName;
			ContainerOrTechnology = containerName;
		}

        /// <summary>
        /// The Company name.
        /// </summary>
        public string CompanyName { get; internal set; }

        /// <summary>
        /// The name of the technology or the container that hosts the running system.
        /// </summary>
        public string ContainerOrTechnology { get; internal set;  }

        /// <summary>
        /// The type of the channel: Admin, Operational, Analytic, Debug.
        /// </summary>
        public ChannelType ChannelType { get; internal set;  }
		
        /// <summary>
        /// A mapping of component to log channel.
        /// </summary>
		private Dictionary<string, ILogChannel> _componentNameToLogChannel = new Dictionary<string, ILogChannel>();

        /// <summary>
        /// Returns the log channel for the given component name.
        /// </summary>
        /// <param name="componentName">The name of the component to get channel for.</param>
        /// <returns>The log channel for the given component name.</returns>
		public ILogChannel this[string componentName] 
		{
			get 
			{
				if (! _componentNameToLogChannel.ContainsKey(componentName))
				{
					LogChannel logchannel = new LogChannel();
					_componentNameToLogChannel[componentName] = logchannel;
					logchannel.Channel = this;
					logchannel.Component = componentName;
				}
				 
				return _componentNameToLogChannel[componentName];
			}
		}
	}
}
